let db=require('../../sql/common')
let Joi=require('joi')
const schema = Joi.object({
    title: Joi.string()
        .min(1)
        .max(20)
        .required(),

    content: Joi.string()
        .required(),
    pic:Joi.string(),
    createTime: Joi.required(),

    tagValue: 
        Joi.any()
        .required()

})
 exports.publish=function(req,res){
    let params = req.body
    const {error,value} =schema.validate(params);
    if(error) return res.send({code:204,msg:error})
    let sql='INSERT INTO list (title,content,pic,createTime,tagValue) VALUES(?,?,?,?,?)'
    db.query(sql,[params.title,params.content,params.pic,params.createTime,params.tagValue],(err,data)=>{
            if(err) return res.send({code:204,msg:'新增失败'})
            res.send({
                code:200,
                msg:'新增成功'
            })
        })
    
   
    
    
    
    
}

